#define STEPS 9
#define LEAF 2
#define COMPLETE 5
#define N 17

Lsystem: 1
derivation length: STEPS

Start: {t = 0; srand(25);}

define: {array
TerminalA[N] = {1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
AngleZA[N] = {187.695, 336.398, 21.7407, 348.032, 32.9473, 331.194, 7.8726, 359.394, 34.8873, 5.74217, 87.8261, 328.919, 337.457, 329.904, 356.08, 337.168, 31.0418},
AngleXA[N] = {160.985, 349.781, 335.051, 348.022, 35.7894, 52.0533, 14.995, 55.3025, 48.9526, 320.681, 262.679, 25.5935, 16.2997, 39.4978, 332.778, 346.436, 29.6849},
LengthA[N] = {1.71394, 6.75509, 1.08847, 1.20445, 0.887877, 1.52123, 1.61121, 3.47552, 1.21208, 3.88854, 0.90734, 3.92286, 6.83184, 1.82582, 1.32469, 3.23642, 0.815054},
Flag[N] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};}

Axiom: A(0, 0)

A(s, l) : (l >= STEPS - LEAF) {t = t + 2;} --> @Tx(1)@Gs@GcTA(s)[A(t - 1, l+1)][A(t, l+1)]@Ge@Gt
A(s, l) : (l >= COMPLETE || s >= N || TerminalA[s] == 1) {t = t + 2;} --> @Tx(1)@Gs@GcGA(s)[A(t - 1, l+1)][A(t, l+1)]@Ge@Gt
A(s, l) : (l < COMPLETE && s < N && TerminalA[s] == 0) --> A(s, l+1)

homomorphism

/*GA(t) : t >= N {t = floor(ran(N));} --> +(AngleXA[t%N])&(AngleZA[t%N])!f(LengthA[t%N])*/
/*TA(t) : t >= N {t = floor(ran(N));} --> +(AngleXA[t%N])&(AngleZA[t%N])!f(LengthA[t%N]),@Tx(2)~l@Tx(1);*/

GA(t) : t >= N {
i = 0; angleXA = 0; while(i < N) {angleXA = angleXA + AngleXA[i]; i = i + 1;} angleXA = angleXA / N;
i = 0; angleZA = 0; while(i < N) {angleZA = angleZA + AngleZA[i]; i = i + 1;} angleZA = angleZA / N;
i = 0; lengthA = 0; while(i < N) {lengthA = lengthA + LengthA[i]; i = i + 1;} lengthA = lengthA / N;
angleXA = angleXA;
angleZA = angleZA;
lengthA = lengthA;
} --> +(angleZA)&(angleXA)!f(lengthA)
TA(t) : t >= N {
i = 0; angleXA = 0; while(i < N) {angleXA = angleXA + AngleXA[i]; i = i + 1;} angleXA = angleXA / N;
i = 0; angleZA = 0; while(i < N) {angleZA = angleZA + AngleZA[i]; i = i + 1;} angleZA = angleZA / N;
i = 0; lengthA = 0; while(i < N) {lengthA = lengthA + LengthA[i]; i = i + 1;} lengthA = lengthA / N;
angleXA = angleXA;
angleZA = angleZA;
lengthA = lengthA;
} --> +(angleZA)&(angleXA)!f(lengthA),@Tx(2)~l@Tx(1);

GA(t) --> +(AngleZA[t])&(AngleXA[t])!f(LengthA[t])
TA(t) --> +(AngleZA[t])&(AngleXA[t])!f(LengthA[t]),@Tx(2)~l@Tx(1);

endlsystem

/*{t = 0; while (Flag[t] == 1) {t = t + 1; if (t >= N) {t = 0; break;}} {Flag[t] = 1;}} */